package com.android.clinic.app.glide;

import com.android.clinic.app.R;

/**
 * Created by dell on 2017/4/8
 */

public class ImageLoader {
    public static final int CENTERCROP = 1; //等比例缩放图片，直到图片的狂高都大于等于ImageView的宽度，然后截取中间的显示。
    public static final int FITCENTER = 2; //等比例缩放图片，宽或者是高等于ImageView的宽或者是高。
    public static final int ALL = 1; //缓存源资源和转换后的资源（即所有版本，默认行为）
    public static final int NONE = 2; //不作任何磁盘缓存。然而，默认的它将仍然使用内存缓存！
    public static final int SOURCE = 3; //仅缓存源资源（原来的全分辨率的图像）。
    public static final int RESULT = 4; //缓存转换后的资源（最终的图像，即降低分辨率后的（或者是转换后的）
    public static final int CROPCIRCLE = 1; //圆形

    private int width; //图片宽度
    private int height; //图片高度
    private float sizeMultiplier=1; //图片缩放 0.1f 作为参数，Glide 将会显示原始图像的10%的大小。
    private int type;  //类型 CENTERCROP或者FITCENTER
    private int animate; //显示动画
    private int transformationtype; //图片转换类型
    private int diskCacheStrategy; //缓存策略
    private boolean skipMemoryCache; //是否跳过内存缓存 任然会缓存在硬盘内
    private int placeHolder; //等待加载图片
    private int error; //加载失败图片

    private ImageLoader(Builder builder) {
        this.width = builder.width;
        this.height = builder.height;
        this.sizeMultiplier = builder.sizeMultiplier;
        this.type = builder.type;
        this.animate = builder.animate;
        this.transformationtype = builder.transformationtype;
        this.diskCacheStrategy = builder.diskCacheStrategy;
        this.skipMemoryCache = builder.skipMemoryCache;
        this.placeHolder = builder.placeHolder;
        this.error = builder.error;
    }

    public void setTransformationtype(int transformationtype) {
        this.transformationtype = transformationtype;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public void setSizeMultiplier(float sizeMultiplier) {
        this.sizeMultiplier = sizeMultiplier;
    }

    public void setType(int type) {
        this.type = type;
    }

    public void setAnimate(int animate) {
        this.animate = animate;
    }

    public void setDiskCacheStrategy(int diskCacheStrategy) {
        this.diskCacheStrategy = diskCacheStrategy;
    }

    public void setSkipMemoryCache(boolean skipMemoryCache) {
        this.skipMemoryCache = skipMemoryCache;
    }

    public void setPlaceHolder(int placeHolder) {
        this.placeHolder = placeHolder;
    }

    public void setError(int error) {
        this.error = error;
    }

    public boolean isSkipMemoryCache() {
        return skipMemoryCache;
    }

    public int getDiskCacheStrategy() {
        return diskCacheStrategy;
    }

    public int getAnimate() {
        return animate;
    }

    public int getTransformationtype() {
        return transformationtype;
    }

    public float getSizeMultiplier() {
        return sizeMultiplier;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public int getType() {
        return type;
    }

    public int getPlaceHolder() {
        return placeHolder;
    }

    public int getError() {
        return error;
    }

    public static class Builder {
        protected int width; //图片宽度
        protected int height; //图片高度
        protected float sizeMultiplier; //图片缩放 0.1f 作为参数，Glide 将会显示原始图像的10%的大小。
        protected int type;  //类型 CENTERCROP或者FITCENTER
        protected int animate; //显示动画
        protected int transformationtype; //图片转换类型
        protected int diskCacheStrategy; //缓存策略
        protected boolean skipMemoryCache; //是否跳过内存缓存 任然会缓存在硬盘内
        protected int placeHolder; //等待加载图片
        protected int error; //加载失败图片

        public Builder() {
            this.width = 0;
            this.height = 0;
            this.sizeMultiplier = 1;
            this.type = FITCENTER;
            this.animate = 0;
            this.transformationtype = 0;
            this.diskCacheStrategy = 0;
            this.skipMemoryCache = false;
            this.placeHolder =0;
            this.error = R.mipmap.ic_launcher;
        }

        public Builder width(int width) {
            this.width = width;
            return this;
        }

        public Builder height(int height) {
            this.height = height;
            return this;
        }

        public Builder sizeMultiplier(int sizeMultiplier) {
            this.sizeMultiplier = sizeMultiplier;
            return this;
        }

        public Builder type(int type) {
            this.type = type;
            return this;
        }

        public Builder animate(int animate) {
            this.animate = animate;
            return this;
        }

        public Builder transformation(int transformationtype) {
            this.transformationtype = transformationtype;
            return this;
        }

        public Builder diskCacheStrategy(int diskCacheStrategy) {
            this.diskCacheStrategy = diskCacheStrategy;
            return this;
        }

        public Builder skipMemoryCache(boolean skipMemoryCache) {
            this.skipMemoryCache = skipMemoryCache;
            return this;
        }

        public Builder placeHolder(int placeHolder) {
            this.placeHolder = placeHolder;
            return this;
        }

        public Builder error(int error) {
            this.error = error;
            return this;
        }

        public ImageLoader build() {
            return new ImageLoader(this);
        }

    }

    public static class HeadBuilder extends Builder {
        public HeadBuilder() {
            this.width = 0;
            this.height = 0;
            this.sizeMultiplier = 0;
            this.type = 0;
            this.animate = 0;
            this.transformationtype = CROPCIRCLE;
            this.diskCacheStrategy = 0;
            this.skipMemoryCache = false;
            this.placeHolder = 0;
            this.error = R.mipmap.ic_launcher;
        }
    }
}
